package phone.example.com.a36kr.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import phone.example.com.a36kr.R;
import phone.example.com.a36kr.bean.RecentBean;
import phone.example.com.a36kr.nettool.NetTool;

/**
 * Created by dllo on 16/8/26.
 */
public class RecentLvAdapter extends BaseAdapter{

    private Context mContext;
    RecentBean recentBeen;

    public void setRecentBeen(RecentBean recentBeen) {
        this.recentBeen = recentBeen;
        notifyDataSetChanged();
    }

    public RecentLvAdapter(Context mContext) {
        this.mContext = mContext;

    }


    @Override
    public int getCount() {
        return recentBeen.getData().getData().size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.items_recent_lv,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();

        }

        viewHolder.desc.setText(recentBeen.getData().getData().get(position).getActivityDesc());
        viewHolder.city.setText(recentBeen.getData().getData().get(position).getActivityCity());
        viewHolder.time.setText(recentBeen.getData().getData().get(position).getActivityTime());
        viewHolder.name.setText(recentBeen.getData().getData().get(position).getActivityName());
        viewHolder.status.setText(recentBeen.getData().getData().get(position).getActivityStatus());
        NetTool netTool = new NetTool();
        Log.d("RecentLvAdapter", recentBeen.getData().getData().get(position).getActivityDesc());
        netTool.getImage(recentBeen.getData().getData().get(position).getActivityImg(),viewHolder.image);



        return convertView;
    }
    private class ViewHolder {

        ImageView image;
        TextView name;
        TextView status;
        TextView time;
        TextView city;
        TextView desc;
        public ViewHolder(View view) {
            image = (ImageView) view.findViewById(R.id.discovery_item_buyer_img);
            name = (TextView) view.findViewById(R.id.discovery_item_buyer_name);
            status = (TextView) view.findViewById(R.id.discovery_item_buyer_status);
            time = (TextView) view.findViewById(R.id.discovery_item_buyer_time);
            city = (TextView) view.findViewById(R.id.discovery_item_buyer_city);
            desc = (TextView) view.findViewById(R.id.discovery_item_buyer_desc);


        }
    }


}
